<?php

namespace App\Listeners\Subscriber;

use App\Events\Auth\Login;

class LoginLogSubscriber extends AbstractSubscriber
{
    /**
     * 注册监听方法
     *
     * @var array
     */
    protected $listen = [
        Login::class => 'login'
    ];

    /**
     * 监听登录事件
     *
     * @param Login $login
     */
    public function login(Login $login)
    {
        $user = $login->user;

        $user->loginLog()->create([
            'ip' => $login->ip,
            'ua' => $login->userAgent,
            'remember' => $login->remember
        ]);
    }
}